//
//  systemMessageCell.swift
//  DingDongZP
//
//  Created by Zhongnan on 16/4/11.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit

class systemMessageCell: UITableViewCell {
    
    var gampView = UIView()
    var titleHead:UILabel?
    var imgView:UIImageView?
    var desc:UILabel?
    var tapBtn:UILabel?
    var rightSymPic:UIImageView?
    var tapCosure:(() ->Void)?
    var models:systemMessageCellModel? {
        didSet{
            updateContent()
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupDefaltContent()
        
    }
    //返回数据update
    func updateContent() {
        
        titleHead?.text = models?.title
        
        let str = LDCommentAPI.getPicApi((models?.image)!)
        let imgurl = NSURL(string: str)
        imgView?.sd_setImageWithURL(imgurl, placeholderImage: UIImage.setImageWithColor(UIColor.grayColor()))
        desc?.text = models?.abstract
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        
    }
    
    func tapCellAction(closure:() ->Void) {
        tapCosure = closure
    }
    
    func setupDefaltContent() {
        
        selectionStyle = UITableViewCellSelectionStyle.None
        backgroundColor = LDGolbalColor.BgGoundGray
        gampView.backgroundColor = UIColor.whiteColor()
        
        titleHead = UILabel.setDetailsLab("叮咚制品紧急声明", fontSize: 16, titleColor: LDFontColor.Black, Alignment: .Left)
        imgView = UIImageView.init(image: UIImage.init(named: "values1.jpg"))
        imgView?.layer.cornerRadius = 2
        desc = UILabel.setDetailsLab("啊快放假快", fontSize: 13, titleColor: LDFontColor.DeepGray, Alignment: .Left)
        
        tapBtn =  UILabel.setDetailsLab("点击查看详情", fontSize: 15, titleColor: LDFontColor.LightBlack, Alignment: .Left)
        rightSymPic = UIImageView.init(image: UIImage.init(named: "侧面小箭头.png"))
        tapBtn?.userInteractionEnabled = true
        
        tapBtn?.bk_whenTapped({ [weak self] in
            if self?.tapCosure != nil {
                self?.tapCosure!()
            }
            })
        
        let divideline = UIView.init()
        divideline.backgroundColor = LDIconColor.LightGray
        gampView.addSubview(divideline)
        
        addSubview(gampView)
        gampView.snp_makeConstraints { (make) in
            make.top.equalTo(LDMargin_V*2)
            make.left.equalTo(LDMargin_V*4)
            make.right.equalTo(-LDMargin_V*4)
            make.bottom.equalTo(0)
        }
        gampView.addSubview(titleHead!)
        gampView.addSubview(imgView!)
        gampView.addSubview(desc!)
        gampView.addSubview(tapBtn!)
        gampView.addSubview(rightSymPic!)
        
        titleHead?.snp_makeConstraints(closure: { (make) in
            make.top.left.equalTo(LDMargin_H*3)
            make.right.equalTo(-LDMargin_H)
            make.height.equalTo(25)
        })
        imgView?.snp_makeConstraints(closure: { (make) in
            make.left.equalTo(LDMargin_H*2)
            make.top.equalTo((titleHead?.snp_bottom)!).offset(LDMargin_H*2)
            make.right.equalTo(-LDMargin_H*2)
            make.height.equalTo(175)
        })
        desc?.snp_makeConstraints(closure: { (make) in
            make.left.right.equalTo(imgView!)
            make.top.equalTo((imgView?.snp_bottom)!).offset(LDMargin_H*1.3)
            make.height.equalTo(20)
        })
        divideline.snp_makeConstraints(closure: { (make) in
            make.left.equalTo(imgView!)
            make.top.equalTo((desc?.snp_bottom)!).offset(LDMargin_H*2)
            make.right.equalTo(-LDMargin_H*2)
            make.height.equalTo(1)
        })
        tapBtn?.snp_updateConstraints(closure: { (make) in
            make.left.equalTo(imgView!)
            make.top.equalTo(divideline.snp_bottom).offset(LDMargin_H*2)
            make.height.equalTo(30)
            make.right.equalTo((rightSymPic?.snp_left)!)
        })
        rightSymPic?.snp_updateConstraints(closure: { (make) in
            
            make.centerY.equalTo(tapBtn!)
            make.right.equalTo(-LDMargin_H*2)
            make.height.equalTo(15)
            make.width.equalTo(10)
        })
    }
    
}
class systemMessageCellModel: NSObject {
    
    var msg_id:Int?
    var title:String?
    var image:String?
    var abstract:String?
    var h5:String?
    var datetime:String?
}
